package com.itheima.controller;

import com.itheima.common.R;
import com.itheima.domain.HomeAdvertise;
import com.itheima.manager.SmsHomeAdvertiseManager;
import org.assertj.core.api.OffsetTimeAssert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class SmsHomeAdvertiseController {

    @Autowired
    SmsHomeAdvertiseManager smsHomeAdvertiseManager;

    //分页查询广告位
    @GetMapping("/home/advertise/list")
    public R findByPage(@RequestParam(required = false)Integer pageSize,
                        @RequestParam(required = false)Integer pageNum,
                        @RequestParam(required = false)Integer type,
                        @RequestParam(required = false)String endTime,
                        @RequestParam(required = false)String name)
    {
        return smsHomeAdvertiseManager.findByPage(pageSize,pageNum,type,endTime,name);
    }

    //添加广告
    @PostMapping("home/advertise/create")
    public R addNew(@RequestBody HomeAdvertise homeAdvertise)
    {
        return smsHomeAdvertiseManager.addNew(homeAdvertise);

    }

    //批量删除
    @PostMapping("/home/advertise/delete")
    public R delete(Integer [] ids)
    {
        return smsHomeAdvertiseManager.delete(ids);
    }

    //修改上下线状态
    @PostMapping("/home/advertise/update/status/{id}")
    public R updateStatus(@PathVariable Integer id, @RequestParam(required = false)Integer status)
    {
        return smsHomeAdvertiseManager.updateStatus(id,status);
    }

    //修改广告
    @PostMapping("/home/advertise/update/{id}")
    public R updateAdvertise(@RequestBody HomeAdvertise advertise,@PathVariable Integer id)
    {
        return smsHomeAdvertiseManager.updateAdvertise(advertise,id);
    }

    //获取广告详情
    @GetMapping("/home/advertise/{id}")
    public R getAdvertise(@PathVariable Integer id)
    {
        return smsHomeAdvertiseManager.getAdvertise(id);

    }

}
